package com.sky.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.realogic.btp.sequence.KSequenceGenerator;
import org.realogic.cfm.domain.KPageResult;
import org.realogic.cfm.persistence.query.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.sky.demo.entity.EntityProduct;
import com.sky.demo.repository.EntityProductDao;
import com.sky.demo.service.EntityProductService;

/**
 * @see EntityProductService
 */
@Service("entityProductService")
public class EntityProductServiceImpl implements EntityProductService {

	// private Log log = LogFactory.getLog(getClass());

	private EntityProductDao entityProductDao;

	public EntityProductServiceImpl() {

	}

	public EntityProductDao getEntityProductDao() {
		return entityProductDao;
	}

	@Autowired
	public void setEntityProductDao(EntityProductDao entityProductDao) {
		this.entityProductDao = entityProductDao;
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int create(final EntityProduct aModel) {
		aModel.setId(KSequenceGenerator.uuidOfLang());
		return entityProductDao.create(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int update(final EntityProduct aModel) {
		return entityProductDao.update(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int remove(final Long aKey) {
		return entityProductDao.remove(aKey);
	}

	public EntityProduct read(final Long aKey) {
		return entityProductDao.read(aKey);
	}

	public KPageResult query(QueryCondition aCondition) {
		List<EntityProduct> tmpList = entityProductDao.query(aCondition);
		KPageResult temp = null;
		if (tmpList != null) {
			temp = new KPageResult(tmpList, aCondition.getTotalSize(), aCondition.getPageNo(), aCondition.getPageSize());
		}
		return temp;
	}

	public PageInfo<EntityProduct> query(Map<String, Object> aCondition, int aPageNo, int aPageSize) {
		return entityProductDao.query(aCondition, aPageNo, aPageSize);
	}

	public List<EntityProduct> query(Map<String, Object> aCondition) {
		return entityProductDao.query(aCondition);
	}

}